var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    strPath: 'www.ejiakanghu.com.cn/iccard/lease/51023003?ids=20200814151552245350775009606991',
    typestr: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options:",options);
    var that = this;    
    if(options.card){
      that.setData({
        typestr:options.card,
        ids:options.order
      })
    }else{
      that.data.strPath = unescape(options.q);
      if(that.data.strPath.indexOf('?') != -1){
        var urlArr = that.data.strPath.split('?');
        var strPath = urlArr[0].split('/')
        that.data.typestr = strPath[strPath.length-1];
        var paramsArr = urlArr[1].split('&')
        that.data.ids = paramsArr[0].split("=")[1];
      }else{
        var urlArr = that.data.strPath.split('/')
        var strPath = urlArr[urlArr.length -1]
        that.data.typestr = strPath;
        that.data.ids = "";
      }
    }

    console.log("params:",that.data.ids,that.data.typestr)
    that.getCardType()
  },
  getCardType() {
    wx.showLoading({
      title: '加载中，请等待',
    })
    var that = this
    app.executeRequest(function (header) {
      wx.request({
        url: app.BASE_URL + '/hospitalized/getIcardBaseInfo',
        header: header,
        data: {
          cardNumber: that.data.typestr
        },
        success: (res) => {
          getApp().hideLoading()
          console.log(res, '卡的详情')
          that.setData({

          })
          if (res.data.data.cardType == 'inpatient' || res.data.data.cardType == 'clk-pay' || res.data.data.cardType == 'clk-free') {
            if (that.data.ids) {
              wx.reLaunch({
                url: '../../../pages/payDeposit/payDeposit?ids=' + that.data.ids+'&card='+that.data.typestr,
              })
            } else {
              wx.reLaunch({
                url: '../selectLease/selectLease?card=' + that.data.typestr
              })
            }
          } else {
            wx.showToast({
              title: '卡类型错误',
            })
            // wx.navigateTo({
            //   url: '../jinglaoyuan/jinglaoyuan',
            // })


          }
        },
        fail: (err) => {
          wx.showToast({
            title: '请求失败',
          })
        }
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})